package com.hncc.kumao.util;

import java.net.URLEncoder;

public class EncodeUtils {

    //将文件路径的各个节点名称进行编码
    public static String encodePath(String path, String encode) throws Exception {
        String[] arr = path.split("/");
        for(int i = 0; i < arr.length; i++) {
            arr[i] = URLEncoder.encode(arr[i], encode);
        }
        String encodePath = "";
        for(int i = 0; i < arr.length; i++) {
            if(arr[i] != null && arr[i].trim().length() > 0) {
                encodePath += "/" + arr[i];
            }
        }
        return encodePath;
    } 
    
    //专门针对FTP路径进行编码
    public static String encodeFTPPath(String path) throws Exception {
        String[] arr = path.split("/");
        for(int i = 0; i < arr.length; i++) {
            arr[i] = new String(arr[i].getBytes("GBK"), "ISO-8859-1");
        }
        String encodePath = "";
        for(int i = 0; i < arr.length; i++) {
            if(arr[i] != null && arr[i].trim().length() > 0) {
                encodePath += "/" + arr[i];
            }
        }
        return encodePath;
    }
}
